<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:rich="http://richfaces.org/rich"
	xmlns:a4j="http://richfaces.org/a4j"
	xmlns:ui="http://java.sun.com/jsf/facelets">

<ui:composition template="/template.jsp">
	<ui:define name="titulo"> <h:outputLabel value="#{msgs['tela.principal']}" />  </ui:define>
	<ui:define name="corpo">
	
			<rich:panel header="Listagem de Usuários">
				<h:panelGrid columns="2">
					<h:form id="frm1">
						<h:commandButton value="Incluir" action="#{usuarioController.incluir}"/>
						<h:commandButton value="Voltar"	action="principal" type="button" immediate="true"/>
					</h:form>
				</h:panelGrid>
				<br/>
				<h:form id="frm2">
					<rich:panel header="#{msgs['button.filtrar']}" style="width: 700px;">
						<h:panelGrid columns="5" width="670">
							<h:outputLabel value="#{msgs['label.usuario']}" />
							<h:panelGroup>
								<h:inputText id="usuario" size="40" maxlength="150"
									value="#{usuarioController.usuario.usuario}" label="Usuário:" />
							</h:panelGroup>
							<h:outputLabel value="#{msgs['label.nomeUsuario']}" />
							<h:panelGroup>
								<h:inputText id="nome" size="40" maxlength="150"
									value="#{usuarioController.usuario.nome}" label="Nome:">
								</h:inputText>
							</h:panelGroup>
							
							<a4j:commandButton value="#{msgs['button.filtrar']}" actionListener="#{usuarioController.filtrar}" reRender="gridUsuario" type="submit"/>
						</h:panelGrid>
					</rich:panel>
				<br/>

				<h:messages layout="table" showSummary="true" showDetail="false" globalOnly="true" styleClass="msgErro" infoClass="msgInfo"	style="font-weight: bold" />
				<rich:dataTable id="gridUsuario" value="#{usuarioController.usuarios}" var="item" rows="5" width="705" styleClass="stable" rowClasses="odd-row, even-row">

					<rich:column sortBy="#{item.usuario}">
						<f:facet name="header">
							<h:outputText value="#{msgs['coluna.usuario']}" />
						</f:facet>
						<h:outputText value="#{item.usuario}" />
					</rich:column>

					<rich:column sortBy="#{item.nome}">
						<f:facet name="header">
							<h:outputText value="#{msgs['coluna.nomeUsuario']}" />
						</f:facet>
						<h:outputText value="#{item.nome}" />
					</rich:column>

					<rich:column width="55" style="text-align: center">
						<f:facet name="header">
							<h:outputText value="Ações" />
						</f:facet>
						
						<h:panelGrid columns="2" width="50">
						<h:commandLink  action="alterarUsuario">
							<f:setPropertyActionListener value="#{item}" target="#{usuarioController.usuario}" />
							<h:graphicImage value="/img/alterar.gif" title="Alterar"/>
						</h:commandLink>
						
						<h:commandLink onclick="#{rich:component('confirmation')}.show();return false">							
							<h:graphicImage value="/img/excluir.jpg" title="Excluir"/>
						</h:commandLink>
						</h:panelGrid>
						
						<rich:modalPanel id="confirmation" width="250" height="135">
							<f:facet name="header">Confirmação</f:facet>

							<h:panelGrid columns="2" width="230">
								<h:graphicImage value="/img/alert.jpg" />
								<h:outputText value="Deseja excluir esse usuário?" />
							</h:panelGrid>
							<h:panelGrid  columns="2" style="margin-left: 70px;">
							<h:commandLink action="#{usuarioController.excluir}">
								<f:setPropertyActionListener value="#{item}"
									target="#{usuarioController.usuario}" />
								<h:commandButton value="Sim" />
							</h:commandLink>
							<h:commandButton value="Não" onclick="#{rich:component('confirmation')}.hide();return false" />
							</h:panelGrid>

						</rich:modalPanel>

					</rich:column>

				</rich:dataTable>
				<br/>
				<rich:datascroller for="gridUsuario" maxPages="20" align="left" />
				</h:form>	
				<br/>
				<br/>
			</rich:panel>


		

	</ui:define>
</ui:composition>

</html>